package com.book.service;/**
 * Created by CoolWen on 2017/5/10.
 */

import com.book.dao.StudentMapper;
import com.book.entity.Pager;
import com.book.entity.Student;
import com.book.entity.UserException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author dell
 * @version 2017-05-10 14:36
 */
@Service("StudentService")
public class StudentServiceImpl implements StudentService {

    @Autowired(required = true)
    StudentMapper studentMapper;

    @Override
    public int addStudent(Student student) {
        return studentMapper.insert(student);
    }

    @Override
    public Student loadByStudentName(String studentName) {
        return studentMapper.loadByStudentName(studentName);
    }

    @Override
    public Student login(String studentName, String studentPassword) {
        Student student = loadByStudentName(studentName);
        if (student == null) {
            throw new UserException("该用户不存在或者密码不正确！");
        }
        if (!student.getStudentPassword().equals(studentPassword))
            throw new UserException("该用户不存在或者密码不正确！");
        return student;
    }

    @Override
    public List<Student> select() {
        return studentMapper.select();
    }

    @Override
    public Pager<Student> find(String name) {
//        Map<String,Object> paras = new HashMap<String, Object>();


        return null;
    }

    @Override
    public Student selectByPrimaryKey(Student student) {
        return studentMapper.selectByPrimaryKey(student);
    }

    @Override
    public int insert(Student record) {
        return studentMapper.insert(record);
    }

    @Override
    public int deleteByPrimaryKey(Integer studentId) {
        return studentMapper.deleteByPrimaryKey(studentId);
    }

    @Override
    public int updateByPrimaryKey(Student record) {
        return studentMapper.updateByPrimaryKey(record);
    }

    @Override
    public int selectCount() {
        return studentMapper.countNum();
    }

    @Override
    public List<Student> selectPageList(int startList, int endList) {
        return studentMapper.selectPageList(startList,endList);
    }


}
